﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Client.Models;
using Newtonsoft.Json;

namespace Client.Base
{
    public partial class FrmInvQuery : DevExpress.XtraEditors.XtraForm
    {
        public FrmInvQuery()
        {
            InitializeComponent();
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                Dictionary<string, string> dc = new Dictionary<string, string>();
                dc.Add("Token",Share.uom.Token);
                
                RetModel rm = Share.PostData("51API/Invoice/GetFP", dc, null);
                if (rm.Success)
                {

                    InvoiceQueryReturn[] iqr = JsonConvert.DeserializeObject<InvoiceQueryReturn[]>(rm.Data.ToString());
                    DataTable dt = new DataTable();
                    dt.Columns.Add("发票流水号");
                    dt.Columns.Add("发票代码");
                    dt.Columns.Add("发票号码");
                    dt.Columns.Add("开票时间");
                    dt.Columns.Add("是否上传");
                    dt.Columns.Add("购方税号");
                    dt.Columns.Add("购方名称");
                    dt.Columns.Add("购方地址电话");
                    dt.Columns.Add("购方银行账号");
                    dt.Columns.Add("合计金额");
                    dt.Columns.Add("合计税额");
                    dt.Columns.Add("备注");
                    dt.Columns.Add("收款人");
                    dt.Columns.Add("开票人");
                    dt.Columns.Add("复核人");
                    for (int i = 0; i < iqr.Length; i++)
                    {
                        DataRow dr = dt.NewRow();
                        dr["发票流水号"] = iqr[i].FPLSH;
                        dr["发票代码"] = iqr[i].FPDM;
                        dr["发票号码"] = iqr[i].FPHM;
                        dr["开票时间"] = iqr[i].KPSJ;
                        if (iqr[i].SCBZ == 0)
                            dr["是否上传"] = "已上传";
                        else
                        {
                            dr["是否上传"] = "未上传";
                        }
                        dr["购方税号"] = iqr[i].GFSH;
                        dr["购方名称"] = iqr[i].GFMC;
                        dr["购方地址电话"] = iqr[i].GFDZDH;
                        dr["购方银行账号"] = iqr[i].GFYHZH;
                        dr["合计金额"] = iqr[i].HJJE;
                        dr["合计税额"] = iqr[i].HJSE;
                        dr["备注"] = iqr[i].BZ;
                        dr["收款人"] = iqr[i].SKR;
                        dr["开票人"] = iqr[i].KPR;
                        dr["复核人"] = iqr[i].FHR;
                        dt.Rows.Add(dr);
                    }
                    gridControl1.DataSource = dt;


                }
                else
                {
                    MessageBox.Show("查询失败！\r\n错误代码:" + rm.ErrCode + "\r\n错误信息：" + rm.ErrInfo);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}